
function category(){
    let url=location.href
    let val=url.indexOf('?')
    val=url.substring(val+1)
    let categoryId=val.split('=')
  return   categoryId=categoryId[1]
}
category()
let  categoryId=category()
////调取接口
function getnav(){
    axios({
        method:'get',
        url:'http://api.yuguoxy.com/api/shop/list/category',
        params:{
            categoryId
        }
    }).then(response=>{
        let data=response.data

        if(data.resultCode==1){
            let list=data.resultInfo.list
            console.log(list);
            showlist(list)
        }
    })
}
getnav()

//渲染对应商品
function showlist(list) {
    let str = list.map(item => {
        return ` <div class="product" onclick="toDetail(${item.id})" >
                    <img src="${item.picture}" alt="">
                    <div class="seleproduct">
                        <p>${item.shop}</p>
                        <p><span>￥${item.price}</span> 1人买</p>
                    </div>
                </div>`
    }).join('')
    $('.content').html(str)
}
function toNav(index) {
    axios({
        method: 'get',
        url: 'http://api.yuguoxy.com/api/shop/category/list',
    }).then(response => {
        let data = response.data
        console.log(data);
        if (data.resultCode == 1) {
            let list = data.resultInfo.list
            let id = list[index].id
            location.href = '../pages/nav.html?id=' + id
            axios({
                method: 'get',
                url: 'http://api.yuguoxy.com/api/shop/list/category',
                params: {
                    categoryId: id
                }
            }).then(response => {
                let data = response.data
                if (data.resultCode == 1) {
                    let list = data.resultInfo.list
                    console.log(list);
                    showlist(list)
                }
            })
        }
    })
}

//返回首页
function blanck(){
    location.href='../pages/index.html'
}